/**
 * Description
 *
 * Creation Date 01/11/2017
 * @author Candy
 */
'use strict';

import mongoose from 'mongoose';
mongoose.connect('mongodb://localhost:27017/Test', {useMongoClient:true});
mongoose.Promise = global.Promise;

const db = mongoose.connection;

db.once('open' ,() => {
	console.log('连接数据库成功')
})

db.on('error', function(error) {
	console.error('Error in MongoDb connection: ' + error);
	mongoose.disconnect();
});

db.on('close', function() {
	console.log('数据库断开，重新连接数据库');
	mongoose.connect('mongodb://localhost:27017/Test', {server:{auto_reconnect:true}});
});

export default db;
